package gblend.infrequentindex;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
/*
* Copyright 2010, Center for Advanced Information Systems,Nanyang Technological University
*
* File name: LargestSubgraphs.java
*
* Abstract: Found out all the largest subgraphs of a fragment
*
* Current Version:      0.1
* Auther:               Jin Changjiu
* Modified Date:        Jan.21,2010
*
*/



import gblend.adjlistgraph.ALGraph;
import java.util.Vector;
import gblend.frequentindex.Vertex;

/**
 *
 * @author cjjin
 */
public class LargestSubgraphs {

  //  private BuildCam bc = new BuildCam();
    Vector<ALGraph> largestSubgraphs = null;

    public  Vector<String> getLargeSubgraph(ALGraph graph)
    {
        Vector<String> subcams = new Vector<String>();
        largestSubgraphs = new Vector<ALGraph>();
        int gsize = graph.getNnum();
       
        for(int i = 0; i<gsize; i++)//choose one node to delete
        {
            ALGraph subgraph = new ALGraph(gsize-1);
            subgraph.setNnum(gsize-1);
            int nodeid = 0;
            for(int j= 0;j<gsize;j++)
            {
                if(j!=i)
                {
                  int m = j;
                  Vertex node = new Vertex();
                  node.setLabel(graph.getNode(j).getLabel());
                  node.setId(nodeid);
                  nodeid++;
                  subgraph.addnode(node);
                  for(int k= 0;k<gsize;k++)
                  {
                     if(k!=i && graph.getEdge(j, k)>0)
                     {
                        int n = k;
                        if(j>i)
                        {
                          m = j-1; //m is the id of new j
                        }
                         
                         if(k>i)
                         {
                           n = k-1;
                         }
                          
                         subgraph.addEdge(m, n);
                         subgraph.getNode(m).setDegree();
                         subgraph.getNode(m).setId(m);

                        }
                    }
                }
            }

            int t = 0;
            for(t=0;t<gsize-1;t++)
            {
                if(subgraph.getNode(t).getDegree()==0)
                {
                   break;
                }
            }
            if(t==gsize-1)
            {
                String subcamstr = BuildCam.buildCam(subgraph);
                if(!subcams.contains(subcamstr))//the unique largest subgraph
                {
                    subcams.addElement(subcamstr);
                    subgraph.setCam(subcamstr);
                    largestSubgraphs.addElement(subgraph);
                }
            }
        }

        return subcams;
    }


    public  Vector<ALGraph>  getSubgraphSet()
    {
        return largestSubgraphs;
    }


}
